Skip to main content

Using Recipes

Adding a Recipe Manager

  1. In the device tree, select the Application object.

    Only one Recipe Manager can be added to an Application.

  2. Click the Project → Add Object → Recipe Manager command.

    The Recipe Manager is added to the device tree.

Adding a recipe definition

Requirement: A Recipe Manager is available in the Application.

  1. In the device tree, click the Recipe Manager object.

  2. Click the Project → Add Object → Recipe Definition command.

    The recipe definition is added below the Recipe Manager.

    Any number of Recipe Definitions can be added to a Recipe Manager.

Defining the storage location

Specifies the storage location for reading and writing recipe files.

Note

The path configuration can vary depending on the PLC used.

In the case of CODESYS Control Win SL, relative paths which refer to a directory in the PLC file system (PlcLogic) must always begin with "./". Otherwise, unexpected behavior may result because recipe file names are usually simply appended to the configured storage location.

Requirement: A Recipe Manager is available in the Application.

Procedure. From the CODESYS programming interface
  1. In the device tree, open the Recipe Manager object.

  2. In the Recipe Manager object, open the Storage tab.

  3. In the File path field, specify the desired path, or click the _cds_icon_button_threedots.png button to use the Input Assistant.

. Calling programmatically

Adding variables to a recipe definition

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

  1. Open the editor of the Recipe Definition by double-clicking the object.

  2. Double-click the blank field below Variable. Specify the name of a variable to define a recipe for. You can use the Input Assistant for this by clicking the _cds_icon_button_threedots.png button).

    Requirement: The variables must be declared in the declaration editor of the program, or the GVL must be declared.

  3. Insert additional fields as needed.

    The values of a variable can be defined separately for each recipe.

Adding a new, empty recipe

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Procedure. From the CODESYS programming interface
  1. Open the editor of the Recipe Definition by double-clicking the object.

  2. Right-click in any cell of the table.

  3. Select the Add a New Recipe command.

  4. Specify a unique name and click OK to confirm.

. Calling programmatically
  • Use the RecipeManCommands.CreateRecipeNoSave (METH) method to create an empty recipe without performing any other actions.

    The NoSave suffix prevents a recipe file from being created in the currently defined storage location.

    Note

    After a recipe is created, it is only automatically saved to a recipe file only if the Save recipe changes to recipe files automatically option is selected on the General tab of the Recipe Manager object.

Saving a recipe file

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Procedure. From the CODESYS programming interface
  1. Open the editor of a Recipe Definition which contains the recipe that should be exported to a recipe file.

  2. Below the recipe, specify the value of the variable for this recipe.

  3. Right-click in any cell of the recipe column of the recipe to save.

  4. Select the Save Recipe command.

  5. Use the Explorer window to specify the desired storage location and file name.

. Calling programmatically

Add a new recipe which contains current PLC values.

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Procedure. From the CODESYS programming interface
  1. Open the editor of the Recipe Definition by double-clicking the object.

  2. Right-click in any cell of the table.

  3. Select the Add a New Recipe command and click OK to confirm.

  4. Right-click in any cell of the recipe column of the newly created recipe.

  5. The programming system must be connected online to the PLC. In the context menu, select the Read Recipe command in order to read the current PLC variable and apply it to the recipe.

. Calling programmatically
  • Use the RecipeManCommands.CreateRecipe (METH) method.

    This function creates a new recipe in the buffer and then automatically reads in the current PLC variables.

    Note

    If the Save recipe changes to recipe files automatically option is selected on the General tab of the Recipe Manager object, then the recipe will also be automatically saved to a recipe file.

Load a recipe from the file system into the buffer

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Procedure. From the CODESYS programming interface
  1. Open the editor of the Recipe Definition where the recipe should be loaded.

  2. Right-click in any cell of the table.

  3. Select the Add a New Recipe command and click OK to confirm.

    A new recipe with the specified name is listed in the table on the right side.

  4. Right-click in any cell of the added recipe.

  5. Select the Load Recipe command and click OK to confirm.

  6. Use the Explorer window to browse and select the desired recipe file.

    The data is displayed.

. Calling programmatically

Loading a recipe from a file

Requirement: A Recipe Manager is available in the application. In a recipe definition, there is a myRec recipe with variable values. A myRec.txt recipe file is located on the file system and contains the entries for this recipe.

Example of the recipe file:

PLC_PRG.bVar:=0
PLC_PRG.iVar:=2
PLC_PRG.dwVar:=35232
PLC_PRG.stVar:='first'
PLC_PRG.wstVar:='123443245'
  1. Double-click the Recipe Definition object in the device tree to open the tabular editor for the definition of the individual recipes.

    You see the myRec column with the current values for this recipe.

  2. Edit the myRec.txt file in an external text editor and replace the variable values with other values that you want to load into the recipe definition in CODESYS. Save the file.

  3. In the recipe definition, click the myRec column and in the context menu click the Load Recipe command.

    A dialog prompt notifies you about the possibly needing to perform an online change when logging in again. An online change is necessary when you change the current values of the recipe variables by loading the recipe.

  4. Click Yes to close the dialog and continue. Select the myRec.txt file from the file explorer for loading.

    The recipe values in the recipe definition are updated according to the values read in the file.

Tip

If you want to overwrite only individual recipe variables with new values, then remove the values for the other variables before loading to the recipe file. Entries without value definitions are not read, and therefore updating leaves these variables unchanged on the controller and in the project.

For values of the data type REAL/LREAL, the hexadecimal value is also written to the recipe file in some cases. This is necessary so that the exactly identical value is restored when converting back. In this case, you change the decimal value and delete the hexadecimal value.

Reading PLC values into a buffered recipe

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Current PLC variable values are read into a buffered recipe.

Procedure. From the CODESYS programming interface
  1. Open the editor of a Recipe Definition which contains the recipe where the PLC variables should be read.

  2. Right-click in any cell of the recipe column of the recipe.

  3. Select the Read Recipe command. This command is available only when the application is online.

. Calling programmatically

Writing recipe values from a recipe file to PLC variables

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

This function loads values from a recipe file to an existing buffered recipe and then writes them to the assigned PLC variables.

Procedure. From the CODESYS programming interface
  1. Open the editor of a Recipe Definition which contains the recipe where the PLC variables should be written to PLC variables.

  2. Right-click in any cell of the recipe column of the recipe which should be written to the PLC.

  3. Select the Load and Write Recipe command. This command is available only when the application is online.

. Calling programmatically

Writing recipe values from a buffered recipe to PLC variables

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Procedure. From the CODESYS programming interface
  1. Open the editor of a Recipe Definition which contains the recipe where the PLC variables should be written to PLC variables.

  2. Right-click in any cell of the recipe column of the recipe which should be written to the PLC.

  3. Select the Write Recipe command. This command is available only when the application is online.

. Calling programmatically

Reading PLC values into a buffered recipe and exporting them to a recipe file.

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Procedure. From the CODESYS programming interface
  1. Open the editor of the Recipe Definition which contains the recipe that should be used for reading the PLC variables and is then writing to a recipe file.

  2. Right-click in any cell of the recipe column of the desired recipe.

  3. Select the Read and Save Recipe command and click OK to confirm your desired online change option in the following dialog.

  4. Select a location and a file name and click Save.

. Calling programmatically

Loading recipe values from the controller

You can apply recipe values on the controller to recipe definitions in the project, even if these definitions have been modified in the project.

Requirement: The Recipe Management in the PLC is option is selected in the Recipe Manager.

  1. Create a recipe definition RecDef1 in the project, containing the variables PLC_PRG.ivar and PLC_PRG.bvar. Insert a recipe R1: value for PLC_PRG.ivar: 33; value for PLC_PRG.bvar: TRUE.

  2. Log in to the controller and download the application.

    The recipe file R1.RecDef1.txtrecipe is saved to the default directory of the controller ($PlcLogic$).

  3. Logout and add another variable PLC_PRG.dwvar to the recipe definition in the project.

  4. Edit the recipe definition file R1.RecDef1.txtrecipe on the device by changing the value for PLC_PRG.ivar from 33 to 34.

    Moreover, add another recipe R2 on the device. To do this, copy the R1.RecDef1.txtrecipe and rename it to R2.RecDef1.txtrecipe. Then edit this file and change the recipe values: PLC_PRG.ivar: 1, PLC_PRG.bvar: FALSE.

    Now two recipes R1 and R2 are available on the device. In the project, there is only R1, and it also contains other values than R1 on the device.

  5. Log in to the controller by means of an online change.

  6. Click the Load Recipes from Device command in the context menu.

    A dialog prompt notifies you that executing the command at the next login may trigger an online change, and that the recipes on the runtime system will overwrite the recipes of the current recipe definition.

  7. Confirm that you want to continue.

    A dialog prompt notifies you that the recipe for PLC_PRG.dwvar loaded on the device cannot yield a value from the controller.

  8. Confirm that you want to continue.

    The value of PLC_PRG.ivar in recipe R1 of the recipe definition in the project changes to 34. The recipe R2 with the values 1 and FALSE is also listed in the recipe definition now. PLC_PRG.dwvar remains in the recipe definition.

Deleting a recipe

Requirement: A Recipe Manager with a Recipe Definition is available in the Application.

Procedure. From the CODESYS programming interface
  1. Open the Recipe Definition where a recipe should be deleted.

  2. Right-click in any cell of the recipe column of the recipe to be deleted.

  3. Select the Remove Recipe command.

. Calling programmatically